package com.atguigu.tingshu.dispatch.job;

import com.atguigu.tingshu.search.client.SearchFeignClient;
import com.atguigu.tingshu.user.client.UserFeignClient;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DispatchHandler {


    /**
     * 入门案例
     */
    @XxlJob("myJob")
    public void myJob() {
        //在任务中获取管理页面传递任务参数
        String jobParam = XxlJobHelper.getJobParam();
        log.info("任务执行了:{}", jobParam);
    }

    /**
     * 分片任务
     */
    @XxlJob("shardJob")
    public void shardJob() {
        log.info("分片任务执行。。");
        int shardTotal = XxlJobHelper.getShardTotal();
        int shardIndex = XxlJobHelper.getShardIndex();
        System.out.println("总分片数 shardTotal = " + shardTotal);
        System.out.println("当前分片索引 shardIndex = " + shardIndex);
    }


    @Autowired
    private SearchFeignClient searchFeignClient;

    /**
     * 定时更新Redis中不同分类下排行top10数据
     */
    @XxlJob("updateLatelyAlbumStatJob")
    public void updateLatelyAlbumStatJob() {
        searchFeignClient.updateLatelyAlbumRanking();
    }


    @Autowired
    private UserFeignClient userFeignClient;

    /**
     * 定时更新VIP状态：处理过期会员
     */
    @XxlJob("updateVipExpireStatus")
    public void updateVipExpireStatus() {
        userFeignClient.updateVipExpireStatus();
    }

}
